from pylog import LogELK, Log


def test():
    # elasticsearch 配置
    elasticsearch_conf = {
        "hosts": ["http://172.31.3.188:9200/"]
    }
    # logstash http 配置
    http_logstash_conf = {
        "host": "172.31.3.188",
        "port": 8001
    }
    # logstash udp 配置
    udp_logstash_conf = {
        "host": "172.31.3.188",
        "port": 8002
    }
    # # logstash tcp 配置
    tcp_logstash_conf = {
        "host": "172.31.3.188",
        "port": 8003
    }
    # kibana 配置
    kibana_conf = {
        "host": "172.31.3.188",
        "port": 5601
    }
    # 实例logger
    logger = Log().init(platform="test").ConsoleLogger()
    # Async
    # logger = LogELK(
    #     elasticsearch_conf=elasticsearch_conf,
    #     logstash_conf=http_logstash_conf,
    #     kibana_conf=kibana_conf).init(platform="test").AsyncHttpLogger()
    # logger = LogELK(
    #     elasticsearch_conf=elasticsearch_conf,
    #     logstash_conf=tcp_logstash_conf,
    #     kibana_conf=kibana_conf).init(platform="test").AsyncTcpLogger()
    # logger = LogELK(
    #     elasticsearch_conf=elasticsearch_conf,
    #     logstash_conf=udp_logstash_conf,
    #     kibana_conf=kibana_conf).init(platform="test").AsyncUdpLogger()
    # Sync
    # logger = LogELK(
    #     elasticsearch_conf=elasticsearch_conf,
    #     logstash_conf=http_logstash_conf,
    #     kibana_conf=kibana_conf).init(platform="test").SyncHttpLogger()
    # logger = LogELK(
    #     elasticsearch_conf=elasticsearch_conf,
    #     logstash_conf=tcp_logstash_conf,
    #     kibana_conf=kibana_conf).init(platform="test").SyncTcpLogger()
    # logger = LogELK(
    #     elasticsearch_conf=elasticsearch_conf,
    #     logstash_conf=udp_logstash_conf,
    #     kibana_conf=kibana_conf).init(platform="test").SyncUdpLogger()

    logger.info("info 测试")
    logger.debug("debug 日志")
    logger.warning("warning 日志")
    try:
        1 / 0
    except Exception as e:
        logger.exception(str(e))
    logger.info("测试加入uuid", extra={"uuid": "abcdefgsadasda"}, )
    logger.info("测试加入uuid", extra={"uuid": "abcdefgsadasda"})
    logger.info("测试加入uuid", extra={"uuid": "abcdefgsadasda"})


if __name__ == '__main__':
    test()
